//
//  FitnessListView.swift
//  Kosspot
//
//  Created by 李鑫 on 2025/7/5.
//

import SwiftUI
import URLImage

struct FitnessListView: View {
    @EnvironmentObject var appState :AppState
    @StateObject var list = SportVM()
    var body: some View {
        VStack {
            List () {
                ForEach(list.listModel?.data ?? []) {item in
                    SportNewCell(model: item)
                        .onTapGesture {
                            print("点击了")
                            // 执行跳转或数据操作
                            appState.navigateTo(.fitnessListDetail(id: item))
                        }
                }
            }
            .listStyle(.plain)
            .scrollIndicators(.hidden)
            .listRowInsets(EdgeInsets())
            .padding(.leading,16)
            .padding(.trailing,16)
            
        }
        .background(Color(hex: "#0A0A0A"))
        .customNavigationBar(title: "健身资讯", backButtonAction: {
            appState.navigateBack()
        }, backgroundColor: UIColor(Color(hex: "#0A0A0A")))
    }
}

#Preview {
    FitnessListView()
}

/*
struct SportNewCellView: View {
    var model: Article
    var body: some View {
            VStack {
                ZStack(alignment:.leading) {
                    Color(hex: "#0A0A0A")
                    if let fullURL = URL(string: model.coverImageUrl){
                        URLImage(url: fullURL) { image in
                            image
                                .resizable()
                                .scaledToFit()
                                .aspectRatio(contentMode: .fill)
                                .frame(width: Bounds.width-32,height: 160)
                                .cornerRadius(16)
                                .padding(.top,12)
                                .clipped() // 确保图片不会超出其边界
                        }
                    } else {
                        Image("25 1")
                            .resizable()
                            .scaledToFit()
                            .aspectRatio(contentMode: .fill)
                            .frame(width: Bounds.width-32,height: 160)
                            .cornerRadius(16)
                            .padding(.top,12)
                            .clipped()
                    }
                    VStack(alignment: .leading, spacing: 8) {
                        Spacer().frame(height: 80)
                        Text(model.title)
                            .font(.system(size: 18))
                            .foregroundColor(.white)
                        
                        Text(model.content)
                            .font(.system(size: 14))
                            .foregroundColor(Color(hex: "#B0B0B0"))
                            .lineLimit(nil)
                        
                        Text(model.publishTimeStr)
                            .font(.system(size: 14))
                            .foregroundColor(.white)
                    }
                    .frame(height: 160)
                    .padding(.leading,16)
                }
                .padding(.top,0)
                .padding(.bottom,0)
            }
        .listRowSeparator(.hidden)
        .listRowInsets(EdgeInsets())
    }
}
*/
